package com.gilgamesh.mall.product.sql;

import com.gilgamesh.mall.sdk.bean.product.ClassficEntity;
import com.gilgamesh.mall.sdk.util.BeanUtil;

/**
 * @author yanm
 * @date 2021/1/11 16:56
 **/
public class ClassficSql {

    public String listClassfics(ClassficEntity entity){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from t_classfic");
        if(BeanUtil.isLogicalNull(entity)){
            return sb.toString();
        }
        int times = 0;
        if(entity.getId()!=null){
            if(times == 0){
                sb.append(" where ");
            }
            if(times>0){
                sb.append(" and ");
            }
            times++;
            sb.append("id = #{id} ");
        }
        if(entity.getClassficName()!=null &&!"".equals(entity.getClassficName())){
            if(times == 0){
                sb.append(" where ");
            }
            if(times>0){
                sb.append(" and ");
            }
            times++;
            sb.append("classfic_name = #{classficName} ");
        }
        if(entity.getLevel()!= null){
            if(times == 0){
                sb.append(" where ");
            }
            if(times>0){
                sb.append(" and ");
            }
            times++;
            sb.append("level = #{level} ");
        }

        if(entity.getRank()!=null){
            if(times == 0){
                sb.append(" where ");
            }
            if(times>0){
                sb.append(" and ");
            }
            times++;
            sb.append("rank = #{rank} ");
        }

        if(entity.getSuperiorId()!=null){
            if(times == 0){
                sb.append(" where ");
            }
            if(times>0){
                sb.append(" and ");
            }
            times++;
            sb.append("superior_id = #{superiorId} ");
        }
//        TODO
        if(entity.getCreateTime()!=null){
            if(times == 0){
                sb.append(" where ");
            }
            if(times>0){
                sb.append(" and ");
            }
            times++;
            sb.append("create_time = #{createTime} ");
        }

        return sb.toString() ;
    }
}
